package com.lsl.learn.springcloud.service;

import com.lsl.learn.springcloud.pojo.Dept;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 服务降级，解耦
 *
 * @ClassName DeptClientServiceFallBackFactory
 * @Description TODO
 * @Author LSL
 * @Date 2019/9/3 22:24
 * @Version 1.0
 * @Email lsl.yx@foxmail.com
 **/
@Component
public class DeptClientServiceFallBackFactory implements FallbackFactory<DeptClientService> {

    @Override
    public DeptClientService create(Throwable throwable) {
        return new DeptClientService() {

            @Override
            public Dept number(Long id) {
                return new Dept()
                        .setDeptNo(id)
                        .setDeptName("该" + id + "编号部门不存在！Provider 已关闭！")
                        .setDbSource("该数据库不存在！");
            }

            @Override
            public List<Dept> all() {
                return null;
            }

            @Override
            public boolean addition(Dept dept) {
                return false;
            }
        };
    }
}
